package jdbc;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class ScanDemo {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("用户名");
        String username = scanner.nextLine();
        System.out.println("密码");
        String password = scanner.nextLine();
        System.out.println("昵称");
        String nickname = scanner.nextLine();
        System.out.println("年龄");
        int age = scanner.nextInt();

        try (Connection connection = DBUti1.getconnection();){
            Statement statement = connection.createStatement();
            String str ="INSERT INTO user(username,password,nickname,age) "+
                        "VALUES('"+username+"','"+password+"','"+nickname+"','"+age+")";
            System.out.println(str);
            int num = statement.executeUpdate(str);
            System.out.println(num>0?"注册成功":"注册失败");
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }


    }
}
